// pages/detail/detail.js
var app = getApp();
var util = require('../../utils/util.js')
const config = require('../../utils/config.js');
var my = require("../../utils/request.js");
var WxParse = require('../../wxParse/wxParse.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {

    //接口地址
    ActivityByID: "activity/",
    ActivityJoin: "activity/", 
    sendMsg:"activity/sendMsg",
    //活动id
    id:'',
    formId:'',
    HotactDetail:{},
    activityUser:false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.showToast({
      title: '加载中',
      icon: 'loading',
      duration: 500
    }) 
    var that=this
    this.setData({ 
      id:options.hid 
      }) 

    that.getActivityDetail();
  },

  //获取活动详情
  getActivityDetail: function(){
    var that=this;
    my.request({
      url:that.data.ActivityByID+that.data.id,
      //data: params,
      method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      }, 
      success: function(res){
        console.log(res)
        that.setData({
          "HotactDetail": res.data.data.activity,
          "activityUser": res.data.data.activityUser,
          "wxParseData": WxParse('html', res.data.data.activity.content)
         })
      }

    })

  },

  //报名
  join:function(e){
    var that = this;
    //判断是否还能参加

    if (that.data.HotactDetail.surplusCount > 0 ){
      if (that.data.activityUser == false){
        //跳转到填写资料界面
        wx.navigateTo({
          url: '../pinfo/pinfo?id=' + that.data.id + '&price=' + that.data.HotactDetail.price
        })
      }else{
        wx.showToast({
          title: '已报名',
          icon: 'loading',
          duration: 500
        }) 
      }
      
    }else{
      wx.showToast({
        title: '名额已满',
        icon: 'loading',
        duration: 500
      }) 
    }

    
    
  
  },

  
  

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function (options) {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function (options) {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function (options) {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function (options) {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function (options) {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function (options) {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (options) {
  
  }
})